package demo.api.trustsign;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import util.HttpClientUtil;

/**
 *  4.3 查询印章集合
 *  通过存储于 SMP中的用户 ID 获得其印章集合。
 * @throws IOException
 */
public class SealFind {

	private static String appKey = "cAwut4VATycNMq17NZeFUD63pe83l2OJ";
    private static String appSecrty = "3BAlrfr7lW8kwlCMfo1dXS8Syn5q5qjS";
    private static String baseUrl = "http://smp-test.szitrus.com.cn/smp-api";
    private static String api = "/api/trustsign/seal/find";

	public static void main(String[] args) throws IOException {
		String url = baseUrl.concat(api);
	    // 请求参数
	    Map<String, String> params = new HashMap<>();
	    params.put("user_id", "1");
	    String resStr =  HttpClientUtil.getResponse(url, params, appKey, appSecrty);
	    JSONObject resJson = JSON.parseObject(resStr);
	    System.out.println(resJson);
	    if("1".equals(resJson.getString("code"))) {
		    JSONArray seals = resJson.getJSONArray("data");
		    for(int i =0 ; i<seals.size();i++) {
		    	System.out.println("第【"+(i+1)+"】印章ID【seal_id】:"+seals.getJSONObject(i).getString("seal_id"));
		    	System.out.println("第【"+(i+1)+"】印章名称【name】:"+seals.getJSONObject(i).getString("name"));
		    	System.out.println("第【"+(i+1)+"】印章图片Base64编码数据【image】:"+seals.getJSONObject(i).getString("image"));
		    	System.out.println("第【"+(i+1)+"】默认印章【is_default】:"+seals.getJSONObject(i).getString("is_default"));
		    	System.out.println("第【"+(i+1)+"】印章类型【type】:"+seals.getJSONObject(i).getString("type"));//other=其他类型, person=个人签字,official=公章
		    }
	    }
	}
}
